{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "a98ebc2d",
   "metadata": {},
   "source": [
    "---------\n",
    "* 本周主要内容：语音识别\n",
    "* 22春_API_人工智能与机器学习_week 12\n",
    "---------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e3bd9e42",
   "metadata": {},
   "source": [
    "# 1.本周内容\n",
    "### 1.1关于麦克风包安装\n",
    "### 1.2优化ASR（自动语音识别）机器人\n",
    "### 1.3连接图灵机器人\n",
    "### 1.4语音合成"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3f7cac3c",
   "metadata": {},
   "source": [
    "## 2.关于麦克风包安装"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6e857334",
   "metadata": {},
   "source": [
    "* 安装 speech_recognition\n",
    "> pip install SpeechRecognition\n",
    "\n",
    "* 安装 PyAudio\n",
    "> Not found name \"PyAudio\"moudle\n",
    "\n",
    "> pip install pipwin\n",
    "\n",
    "> pipiwin install PyAudio"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a8ad1d26",
   "metadata": {},
   "source": [
    "## 3.优化ASR（自动语音识别）机器人"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "449cb969",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 百度密钥\n",
    "API_KEY = 'BhfEzICwDdWI6BueF9d9zgeG'\n",
    "SECRET_KEY = 'tcMYiy8ikG5rZC9URKakIuQmy11Fvd7b'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "0fbe78d3",
   "metadata": {},
   "outputs": [],
   "source": [
    "from bdasr import fetch_token,asr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "612744df",
   "metadata": {},
   "outputs": [
    {
     "ename": "DemoError",
     "evalue": "scope is not correct",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mDemoError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-10-6a589be75956>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mRasi_token\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mfetch_token\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mAPI_KEY\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mSECRET_KEY\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      2\u001b[0m \u001b[0mRasi_token\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\API\\week 12\\bdasr.py\u001b[0m in \u001b[0;36mfetch_token\u001b[1;34m(API_KEY, SECRET_KEY)\u001b[0m\n\u001b[0;32m     52\u001b[0m     \u001b[1;32mif\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;34m'access_token'\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mresult\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mkeys\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mand\u001b[0m \u001b[1;34m'scope'\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mresult\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mkeys\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     53\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mSCOPE\u001b[0m \u001b[1;32mand\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;32mnot\u001b[0m \u001b[0mSCOPE\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mresult\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'scope'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msplit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m' '\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m  \u001b[1;31m# SCOPE = False 忽略检查\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 54\u001b[1;33m             \u001b[1;32mraise\u001b[0m \u001b[0mDemoError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'scope is not correct'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     55\u001b[0m         \u001b[1;32mreturn\u001b[0m \u001b[0mresult\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'access_token'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     56\u001b[0m     \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mDemoError\u001b[0m: scope is not correct"
     ]
    }
   ],
   "source": [
    "Rasi_token = fetch_token(API_KEY,SECRET_KEY)\n",
    "Rasi_token"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "454e1a63",
   "metadata": {},
   "outputs": [],
   "source": [
    "import speech_recognition\n",
    "r = speech_recognition.Recognizer()\n",
    "with speech_recognition.Microphone() as source:\n",
    "    audio = r.listen(source)\n",
    "# 将数据保存到wav文件中\n",
    "with open(\"1.wav\", \"wb\") as f: \n",
    "    f.write(audio.get_wav_data(convert_rate=16000))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "c5b2d9cf",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'Rasi_token' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-10-8eb770428c68>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0masr_output\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0meval\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mRasi_token\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\"1.wav\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'result'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      2\u001b[0m \u001b[0masr_output\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mNameError\u001b[0m: name 'Rasi_token' is not defined"
     ]
    }
   ],
   "source": [
    "asr_output = eval((Rasi_token,\"1.wav\"))['result'][0]\n",
    "asr_output"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ed1db1da",
   "metadata": {},
   "source": [
    "## 4.连接图灵机器人\n",
    "\n",
    "* API V2.0是基于图灵机器人平台语义理解、深度学习等核心技术，为广大开发者和企业提供的在线服务和开发接口。\n",
    "\n",
    "* 接口地址:\n",
    "> http://openapi.turingapi.com/openapi/api/v2\n",
    "\n",
    "* 请求方式\n",
    "> POST\n",
    "\n",
    "* 请求参数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "3ed38cb5",
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "277977a3",
   "metadata": {},
   "outputs": [],
   "source": [
    "TL_KEY = \"******\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "98e43034",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "def TL_API(key,text):\n",
    "    TL_URL = \"http://openapi.turingapi.com/openapi/api/v2\"\n",
    "\n",
    "    payload={\n",
    "        \"reqType\":0,\n",
    "        \"perception\": {\n",
    "            \"inputText\": {\n",
    "                \"text\": \"text\"\n",
    "            },\n",
    "        },\n",
    "        \"userInfo\": {\n",
    "            \"apiKey\": TL_KEY,\n",
    "            \"userId\": \"00001\"\n",
    "        }\n",
    "    }\n",
    "    res = requests.post(TL_URL,data= json.dumps(payload))\n",
    "    return res.json()['results'][0]['values']['text']"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2176789f",
   "metadata": {},
   "source": [
    "## 4.1接入对话机器人的流程\n",
    "\n",
    "> 1.录制音频\n",
    "\n",
    "> 2.语音识别-（百度ASR接口）-音频转文本信息\n",
    "\n",
    "> 3.图灵API-（进行文字输入和文字回复）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f9d82db4",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1. 录制音频\n",
    "import speech_recognition\n",
    "r = speech_recognition.Recognizer()\n",
    "with speech_recognition.Microphone() as source:\n",
    "    audio = r.listen(source)\n",
    "# 将数据保存到wav文件中\n",
    "with open(\"1.wav\", \"wb\") as f: \n",
    "    f.write(audio.get_wav_data(convert_rate=16000))\n",
    "    \n",
    "# 2. 语音识别    \n",
    "Rasi_token = fetch_token(API_KEY,SECRET_KEY)\n",
    "asr_output = eval((Rasi_token,\"1.wav\"))['result'][0]\n",
    "\n",
    "# 3. 图灵API\n",
    "TL_API(TL_KEY,asr_output)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a1d1c347",
   "metadata": {},
   "source": [
    "## 5. 语音合成测试"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "af92ec09",
   "metadata": {},
   "outputs": [],
   "source": [
    "# coding=utf-8\n",
    "import sys\n",
    "import json\n",
    "\n",
    "IS_PY3 = sys.version_info.major == 3\n",
    "if IS_PY3:\n",
    "    from urllib.request import urlopen\n",
    "    from urllib.request import Request\n",
    "    from urllib.error import URLError\n",
    "    from urllib.parse import urlencode\n",
    "    from urllib.parse import quote_plus\n",
    "else:\n",
    "    import urllib2\n",
    "    from urllib import quote_plus\n",
    "    from urllib2 import urlopen\n",
    "    from urllib2 import Request\n",
    "    from urllib2 import URLError\n",
    "    from urllib import urlencode\n",
    "\n",
    "TEXT = \"欢迎使用百度语音合成。\"\n",
    "\n",
    "# 发音人选择, 基础音库：0为度小美，1为度小宇，3为度逍遥，4为度丫丫，\n",
    "# 精品音库：5为度小娇，103为度米朵，106为度博文，110为度小童，111为度小萌，默认为度小美 \n",
    "PER = 4\n",
    "# 语速，取值0-15，默认为5中语速\n",
    "SPD = 5\n",
    "# 音调，取值0-15，默认为5中语调\n",
    "PIT = 5\n",
    "# 音量，取值0-9，默认为5中音量\n",
    "VOL = 5\n",
    "# 下载的文件格式, 3：mp3(default) 4： pcm-16k 5： pcm-8k 6. wav\n",
    "AUE = 6\n",
    "\n",
    "FORMATS = {3: \"mp3\", 4: \"pcm\", 5: \"pcm\", 6: \"wav\"}\n",
    "FORMAT = FORMATS[AUE]\n",
    "\n",
    "CUID = \"123456PYTHON\"\n",
    "\n",
    "TTS_URL = 'http://tsn.baidu.com/text2audio'\n",
    "\n",
    "\n",
    "class DemoError(Exception):\n",
    "    pass\n",
    "\n",
    "\n",
    "\"\"\"  TOKEN start \"\"\"\n",
    "\n",
    "TOKEN_URL = 'http://aip.baidubce.com/oauth/2.0/token'\n",
    "SCOPE = 'audio_tts_post'  # 有此scope表示有tts能力，没有请在网页里勾选\n",
    "\n",
    "\n",
    "# def fetch_token():\n",
    "#    print(\"fetch token begin\")\n",
    "#    params = {'grant_type': 'client_credentials',\n",
    "#              'client_id': API_KEY,\n",
    "#             'client_secret': SECRET_KEY}\n",
    "#    post_data = urlencode(params)\n",
    "#    if (IS_PY3):\n",
    "#        post_data = post_data.encode('utf-8')\n",
    "#   req = Request(TOKEN_URL, post_data)\n",
    "#    try:\n",
    " #       f = urlopen(req, timeout=5)\n",
    "  #      result_str = f.read()\n",
    "   # except URLError as err:\n",
    "    #    print('token http response http code : ' + str(err.code))\n",
    "     #   result_str = err.read()\n",
    "    # if (IS_PY3):\n",
    "      #  result_str = result_str.decode()\n",
    "\n",
    "    # print(result_str)\n",
    "    # result = json.loads(result_str)\n",
    "    # print(result)\n",
    " #   if ('access_token' in result.keys() and 'scope' in result.keys()):\n",
    "    #    if not SCOPE in result['scope'].split(' '):\n",
    "    #        raise DemoError('scope is not correct')\n",
    "        # print('SUCCESS WITH TOKEN: %s ; EXPIRES IN SECONDS: %s' % (result['access_token'], result['expires_in']))\n",
    "     #   return result['access_token']\n",
    "  #  else:\n",
    "   #     raise DemoError('MAYBE API_KEY or SECRET_KEY not correct: access_token or scope not found in token response')\n",
    "\n",
    "\n",
    "\"\"\"  TOKEN end \"\"\"\n",
    "\n",
    "def tts(token,TEXT):\n",
    "    tex = quote_plus(TEXT)  # 此处TEXT需要两次urlencode\n",
    "    print(tex)\n",
    "    params = {'tok': token, 'tex': tex, 'per': PER, 'spd': SPD, 'pit': PIT, 'vol': VOL, 'aue': AUE, 'cuid': CUID,\n",
    "              'lan': 'zh', 'ctp': 1}  # lan ctp 固定参数\n",
    "\n",
    "    data = urlencode(params)\n",
    "    print('test on Web Browser' + TTS_URL + '?' + data)\n",
    "\n",
    "    req = Request(TTS_URL, data.encode('utf-8'))\n",
    "    has_error = False\n",
    "    try:\n",
    "        f = urlopen(req)\n",
    "        result_str = f.read()\n",
    "\n",
    "        headers = dict((name.lower(), value) for name, value in f.headers.items())\n",
    "\n",
    "        has_error = ('content-type' not in headers.keys() or headers['content-type'].find('audio/') < 0)\n",
    "    except  URLError as err:\n",
    "        print('asr http response http code : ' + str(err.code))\n",
    "        result_str = err.read()\n",
    "        has_error = True\n",
    "\n",
    "    save_file = \"error.txt\" if has_error else 'result.' + FORMAT\n",
    "    with open(save_file, 'wb') as of:\n",
    "        of.write(result_str)\n",
    "\n",
    "    if has_error:\n",
    "        if (IS_PY3):\n",
    "            result_str = str(result_str, 'utf-8')\n",
    "        print(\"tts api  error:\" + result_str)\n",
    "\n",
    "    print(\"result saved as :\" + save_file)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "fa0b9f8d",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'Rasi_token' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-16-490ac64b76f1>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mtts\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mRasi_token\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mTEXT\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m: name 'Rasi_token' is not defined"
     ]
    }
   ],
   "source": [
    "tts(Rasi_token,TEXT)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9448e685",
   "metadata": {},
   "source": [
    "# 6. 在jupyter中播放音频文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "58ad60b7",
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'pydub'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-14-e256171e7dc5>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[0mpydub\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mAudioSegment\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      2\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mpydub\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mplayback\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mplay\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      3\u001b[0m \u001b[0msong\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mAudioSegmen\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfrom_wav\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'result.wav'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      4\u001b[0m \u001b[0mpaly\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msong\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'pydub'"
     ]
    }
   ],
   "source": [
    "from pydub import AudioSegment\n",
    "from pydub.playback import play\n",
    "song = AudioSegmen.from_wav('result.wav')\n",
    "paly(song)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "74485e4b",
   "metadata": {},
   "source": [
    "## 7.智能对话机器人最终版"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "1bf014da",
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'speech_recognition'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-17-0d5028bcc0d2>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;31m# 1. 录制音频\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[1;32mimport\u001b[0m \u001b[0mspeech_recognition\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      3\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mpydub\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mAudioSegment\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      4\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mpydub\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mplayback\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mplay\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      5\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'speech_recognition'"
     ]
    }
   ],
   "source": [
    "# 1. 录制音频\n",
    "import speech_recognition\n",
    "from pydub import AudioSegment\n",
    "from pydub.playback import play\n",
    "\n",
    "r = speech_recognition.Recognizer()\n",
    "with speech_recognition.Microphone() as source:\n",
    "    audio = r.listen(source)\n",
    "# 将数据保存到wav文件中\n",
    "with open(\"1.wav\", \"wb\") as f: \n",
    "    f.write(audio.get_wav_data(convert_rate=16000))\n",
    "    \n",
    "# 2. 语音识别    \n",
    "Rasi_token = fetch_token(API_KEY,SECRET_KEY)\n",
    "asr_output = eval((Rasi_token,\"1.wav\"))['result'][0]\n",
    "\n",
    "# 3. 图灵API\n",
    "TL_result = TL_API(TL_KEY,asr_output)\n",
    "\n",
    "# 4. 语音合成技术 TTS-->产生result.wav\n",
    "tts(Rasi_token,TL_result)\n",
    "\n",
    "# 5. 在jupyter中进行音频播放\n",
    "song = AudioSegmen.from_wav('result.wav')\n",
    "paly(song)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
